package javabase.biji;

import org.junit.Test;

/**
 * @Auther: luzhanshi
 * @Date: 2021/2/1 - 02 - 01 - 15:46 
 * @Description: javabase.biji
 * @version: 1.0
 */
public class _21多态 {
    //    父类
    public class Animal {
        public String name = "小动物";

        public void dosomething() {
            System.out.println("动物都要吃东西!!!");
        }
    }

    //    子类
    public class Dog extends Animal {
        public String name = "旺旺";
        public int age = 11;

        @Override
        public void dosomething() {
            System.out.println("狗吃屎!!!");
        }

        public void eat() {
            System.out.println("eat");
        }
    }

    //    执行:
    public class Demo {

        public  void test() {
            Animal animal = new Dog();
            System.out.println(animal.name);//小动物
//        System.out.println(animal.age);//编译报错,因为Animal类里面没有age变量
            animal.dosomething();//狗吃屎
//        animal.eat();//编译报错,因为Animal类里面没有eat方法
        }
    }

    @Test
    public void test(){
        new Demo().test();
    }
}
